<template>
    <div class="tree-node" :style="{ paddingLeft: depth * 20 + 'px' }">
      <div class="node-content">
        <span 
          class="checkbox"
          :class="{ checked: node.selected }"
          @click="toggleSelect"
        ></span>
        <span class="label">{{ node.label }}</span>
        <span 
          v-if="hasChildren"
          class="expand-icon"
          @click="toggleExpand"
        >
          {{ node.expanded ? '-' : '+' }}
        </span>
      </div>
      <div v-show="node.expanded" class="children">
        <custom-tree-node
          v-for="child in node.children"
          :key="child.id"
          :node="child"
          :depth="depth + 1"
          @toggle-select="$emit('toggle-select', $event)"
        />
      </div>
    </div>
  </template>
  
  <script lang="ts">

  interface TreeNode {
    id: number;
    label: string;
    children?: TreeNode[];
    selected?: boolean;
    expanded?: boolean;
    visible?: boolean;
  }
  import {Component, Vue,Prop} from 'vue-property-decorator';
  @Component({
    name: 'CustomTreeNode',
    methods: {},
    components: {}

    })
  export default class CustomTreeNode extends Vue {
    @Prop({ required: true }) node!: TreeNode;
    @Prop({ default: 0 }) depth!: number;
  
    get hasChildren() {
      return this.node.children && this.node.children.length > 0;
    }
  
    toggleSelect() {
      this.node.selected = !this.node.selected;
      this.$emit('toggle-select', this.node);
    }
  
    toggleExpand() {
      this.node.expanded = !this.node.expanded;
    }
  }
  </script>
  
  <style scoped>
  .custom-tree-container {
    max-height: 60vh;
    overflow-y: auto;
  }
  
  .tree-search {
    padding: 8px;
    border-bottom: 1px solid #eee;
  }
  
  .search-input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
  }
  
  .tree-node {
    padding: 4px 0;
  }
  
  .node-content {
    display: flex;
    align-items: center;
    padding: 4px 0;
    cursor: pointer;
    transition: background 0.3s;
  }
  
  .node-content:hover {
    background: #f5f7fa;
  }
  
  .checkbox {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 1px solid #dcdfe6;
    border-radius: 3px;
    margin-right: 8px;
    position: relative;
  }
  
  .checkbox.checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid #409eff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
  }
  
  .label {
    flex: 1;
    user-select: none;
  }
  
  .expand-icon {
    width: 20px;
    text-align: center;
    margin-left: 8px;
  }
  
  .children {
    margin-left: 12px;
  }
  </style>